package com.atguigu.gmall.pms.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;

@Configuration
@Slf4j
public class RabbitmqConfig {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
        //没有到达交换机
        rabbitTemplate.setConfirmCallback(( correlationData,  ack,  cause)->{
            if (!ack){
            log.error("消息没有到达交换机，原因:{}",cause);
            }
        });
        //没有到达队列
        rabbitTemplate.setReturnCallback(( message,  replyCode,  replyText,  exchange,  routingKey)->{
            log.error("消息没有到达队列，交换机：{}，路由键：{}，消息：{}，响应状态码：{}，响应文本：{}",
                        exchange,routingKey,new String(message.getBody()),replyCode,replyText);
        });
    }
}
